package com.github.bufan.dubbo;

import com.github.bufan.dubbo.api.HelloService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;

import java.util.concurrent.ThreadLocalRandom;


@Service(filter = {"transportip"})
public class HelloServiceImpl implements HelloService {
    @Override
    public String method1(String name) {
        try {
            Thread.sleep(ThreadLocalRandom.current().nextInt(100));
        }catch (Exception e){
            e.printStackTrace();
        }
        return "hello1:"+name;
    }

    @Override
    public String method2(String name) {
        try {
            Thread.sleep(ThreadLocalRandom.current().nextInt(100));
        }catch (Exception e){
            e.printStackTrace();
        }
        return "hello2:"+name;
    }

    @Override
    public String method3(String name) {
        try {
            Thread.sleep(ThreadLocalRandom.current().nextInt(100));
        }catch (Exception e){
            e.printStackTrace();
        }
        return "hello3:"+name;
    }

    @Override
    public String browserIp(String ip) {
        RpcContext rpcContext = RpcContext.getContext();
        String browserIp = rpcContext.getAttachment("browserIp");

        return "您的ip地址为 ："+browserIp;
    }
}
